home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / PROBLEMS / BENCHMARK / BUBBLESORT / bubbletest / AnsiC_2 / c / source
C/C++ Source or Header  |  1992-06-17  |  1KB  |  72 lines

  1. /*       bubbletest source file          */
  2. /*                                       */  
  3. /*   compiled using Acorn C Release 4    */
  4. /*                                       */
  5.  
  6. #include <stdio.h>
  7. #define BOOL int
  8. #define TRUE 1
  9. #define FALSE 0
  10. #define length 1000
  11.  
  12. void init_array(void);
  13. void bubblesort(void);
  14. void print_array(void);
  15.  
  16. int array[length];
  17.  
  18. int main()
  19. {
  20.   init_array();
  21.   print_array();
  22.   os_cli("show time1");
  23.   bubblesort();
  24.   os_cli("show time1");
  25.   print_array();
  26. }
  27.  
  28. void init_array()
  29. {
  30.   int count;
  31.   int pseudorandom=123456;
  32.   for (count=0;count<length;count++)
  33.   {
  34.     pseudorandom=(pseudorandom + 234567) % 567 + 345;
  35.     array[count]=pseudorandom;
  36.   }
  37. }
  38.  
  39. void bubblesort()
  40. {
  41.   register int temp;
  42.   register int *p;
  43.   register int *end;
  44.   BOOL sorted;
  45.   end=array+length-2;
  46.   do
  47.   {
  48.     sorted=TRUE;
  49.     p=array; temp=*p;
  50.     do
  51.     {
  52.       if (temp>*(p+1))
  53.       {
  54.         *p=*(p+1);
  55.         *(p+1)=temp; sorted=FALSE;
  56.       }
  57.       else temp=*(p+1);
  58.     }
  59.     while ((p++)!=end);
  60.   }
  61.   while (!sorted);
  62. }
  63.  
  64. void print_array()
  65. {
  66.   int i;
  67.   for (i=0;i<1000;i++)
  68.   {
  69.     printf("%d\n",array[i]);
  70.   }
  71. }
  72.